<template>
  <div class="history__list-div">
    <van-collapse v-model="activeNames">
      <van-collapse-item
        v-for="(item,index) in orderList"
        :key="index"
        :name="index"
        :title="item.order"
        :value="item.status"
        :label="item.money"
      >
        <van-cell-group
          v-for="(it,idx) in item.listContractInfo"
          :key="idx"
          :name="idx"
          :title="it.ctName"
        >
          <van-cell
            v-for="(i,x) in it.listMaterialInfo"
            :key="x"
            :name="x"
            :title="i.materialName"
            :value="i.number"
            :label="i.price"
          />
        </van-cell-group>
      </van-collapse-item>
    </van-collapse>
  </div>
</template>

<script>
export default {
  data() {
    return {
      activeNames: ["1"],
      dataList: [
        {
          order_no: "202004050001",
          order_amount: "300987",
          order_status: "1",
          contractlist: [
            {
              vbill_code: "889900",
              ct_name: "疯牛病疫苗合同1",
              materiallist: [
                {
                  material_code: "500081",
                  material_name: "疯牛病疫苗1号",
                  nprice: 16388,
                  num: 30,
                },
              ],
            },
            {
              vbill_code: "889901",
              ct_name: "禽流感疫苗合同1",
              materiallist: [
                {
                  material_code: "500091",
                  material_name: "禽流感疫苗1号",
                  nprice: 16388,
                  num: 25,
                },
                {
                  material_code: "500092",
                  material_name: "禽流感疫苗2号",
                  nprice: 16388,
                  num: 10,
                },
              ],
            },
          ],
        },
        {
          order_no: "202004050002",
          order_amount: "300987",
          order_status: "2",
          contractlist: [
            {
              vbill_code: "889900",
              ct_name: "禽流感疫苗合同",
              materiallist: [
                {
                  material_code: "500091",
                  material_name: "禽流感疫苗1号",
                  nprice: 16388,
                  num: 30,
                },
              ],
            },
          ],
        },
      ],
      orderList: [],
    };
  },

  mounted() {
    this.getOrderInfo();
  },
  methods: {
    getOrderInfo() {
      this.$axios
        .get(`/api/admin/order-info/order?merchantNo=90001`)
        .then((res) => {
          this.orderList = res.data.data;
          console.log("获取订单列表返回信息：");
          console.log(this.orderList);

          this.orderList.forEach((item, index) => {
            item.order = "订单号：" + item.orderNo;
            if (item.orderStatus === -1) {
              item.status = "失败";
            } else if (item.orderStatus === 1) {
              item.status = "处理中";
            } else if (item.orderStatus === 2) {
              item.status = "成功";
            }
            item.money = "总金额：" + item.orderAmount + "元";
            item.listContractInfo.forEach((it, idx) => {
              it.listMaterialInfo.forEach((i, x) => {
                i.number = "×" + i.num + "(" + i.cunitId + ")";
                i.price = "单价：" + i.nprice + "元";
              });
            });
          });
        })
        .catch((err) => {
          console.log(err);
        });
    },
  },
};
</script>
<style lang='css' scoped>
.history__list-div {
  margin-top: 50px;
}
</style>